package pers.archives.auth.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pers.archives.auth.mapper.UserMapper;
import pers.archives.auth.service.UserService;
import pers.archives.common.entity.User;
import pers.archives.common.utils.DateUtil;
import pers.archives.common.utils.UUIDUtil;

import java.util.Date;

/* 操作用户实现
 *@program:archives-parent
 *@author: 赵浩浩
 *@Time: 2020/10/1  18:27
 */
@Service
public class UserServiceImpl implements UserService {

    private final UserMapper userMapper;

    private final UUIDUtil uuidUtil;

    @Autowired
    public UserServiceImpl(UserMapper userMapper, UUIDUtil uuidUtil) {
        this.userMapper = userMapper;
        this.uuidUtil = uuidUtil;
    }

    /**
     * 创建用户
     * @param user
     * @return
     */
    @Override
    public int addUser(User user) {
        //获取当前系统时间
        Date date = DateUtil.getCurrentTime();
        user.setUserId(uuidUtil.nextId());
        user.setCreateTime(date);
        user.setUpdateTime(date);
        return userMapper.addUser(user);
    }
}
